
import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router'

const routes = [
    {
        name: 'Index',
        path: '/',
        meta: {title: '首页'},
        component: () => import('@/views/Index.vue')
    },
    {
        path: '/admin/login',
        name: 'admin-login',
        meta: {title: '控制台登录'},
        component: () => import('@/views/admin/Login.vue')
    },
    {
        path: '/login',
        name: 'login',
        meta: {title: '用户登录'},
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/register',
        name: 'register',
        meta: {title: '用户注册'},
        component: () => import('@/views/Register.vue')
    },
    {
        name: "resetpassword",
        path: "/resetpassword",
        meta: { title: "重置密码" },
        component: () => import("@/views/Resetpassword.vue"),
    },
    {
        path: '/admin',
        name: 'admin',
        redirect: '/admin/dashboard',
        component: () => import('@/views/admin/Home.vue'),
        meta: {title: 'Geek-AI 控制台'},
        children: [
            {
                path: '/admin/dashboard',
                name: 'admin-dashboard',
                component: () => import('@/views/admin/Dashboard.vue'),
                meta: {title: '仪表盘'},
            },
            {
                path: '/admin/user',
                name: 'admin-user',
                component: () => import('@/views/admin/User.vue'),
                meta: {title: '用户管理'},
            },
            {
                path: '/admin/app',
                name: 'admin-app',
                component: () => import('@/views/admin/Apps.vue'),
                meta: {title: '应用列表'},
            },
            {
                path: '/admin/app/type',
                name: 'admin-app-type',
                component: () => import('@/views/admin/AppType.vue'),
                meta: {title: '应用分类'},
            },
            {
                path: '/admin/apikey',
                name: 'admin-apikey',
                component: () => import('@/views/admin/ApiKey.vue'),
                meta: {title: 'API-KEY管理'},
            },
            {
                path: '/admin/chat/model',
                name: 'admin-chat-model',
                component: () => import('@/views/admin/ChatModel.vue'),
                meta: {title: '语言模型'},
            },
            {
                path: '/admin/product',
                name: 'admin-product',
                component: () => import('@/views/admin/Product.vue'),
                meta: {title: '充值产品'},
            },
            {
                path: '/admin/order',
                name: 'admin-order',
                component: () => import('@/views/admin/Order.vue'),
                meta: {title: '充值订单'},
            },
            {
                path: '/admin/redeem',
                name: 'admin-redeem',
                component: () => import('@/views/admin/Redeem.vue'),
                meta: {title: '兑换码管理'},
            },
            {
                path: '/admin/functions',
                name: 'admin-functions',
                component: () => import('@/views/admin/Functions.vue'),
                meta: {title: '函数管理'},
            },
            {
                path: '/admin/chats',
                name: 'admin-chats',
                component: () => import('@/views/admin/ChatList.vue'),
                meta: {title: '对话管理'},
            },
            {
                path: '/admin/images',
                name: 'admin-images',
                component: () => import('@/views/admin/ImageList.vue'),
                meta: {title: '绘画管理'},
            },
            {
                path: '/admin/medias',
                name: 'admin-medias',
                component: () => import('@/views/admin/Medias.vue'),
                meta: {title: '音视频管理'},
            },
            {
                path: '/admin/manger',
                name: 'admin-manger',
                component: () => import('@/views/admin/Manager.vue'),
                meta: {title: '管理员'},
            },
            {
                path: '/admin/system',
                name: 'admin-system',
                component: () => import('@/views/admin/SysConfig.vue'),
                meta: {title: '系统设置'},
            },
            {
                path: '/admin/powerLog',
                name: 'admin-powerLog',
                component: () => import('@/views/admin/PowerLog.vue'),
                meta: {title: '算力日志'},
            },
            {
                path: '/admin/loginLog',
                name: 'admin-loginLog',
                component: () => import('@/views/admin/LoginLog.vue'),
                meta: {title: '登录日志'},
            }
        ]
    },
    {
        path: '/home',
        name: 'home',
        redirect: '/chat',
        component: () => import('@/views/Home.vue'),
        children: [
            {
                path: '/chat',
                name: 'chat',
                meta: {title: '创作中心'},
                component: () => import('@/views/ChatPlus.vue'),
            },
            {

                path: '/chat/:id',
                name: 'chat-id',
                meta: {title: '创作中心'},
                component: () => import('@/views/ChatPlus.vue'),
            },
            {

                path: '/mj',
                name: 'image-mj',
                meta: {title: 'MidJourney 绘画中心'},
                component: () => import('@/views/ImageMj.vue'),
            },
            {

                path: '/sd',
                name: 'image-sd',
                meta: {title: 'stable diffusion 绘画中心'},
                component: () => import('@/views/ImageSd.vue'),
            },
            {

                path: '/dalle',
                name: 'dalle',
                meta: {title: 'DALLE-3'},
                component: () => import('@/views/Dalle.vue'),
            },
            {

                path: '/suno',
                name: 'suno',
                meta: {title: 'Suno音乐创作'},
                component: () => import('@/views/Suno.vue'),
            },
            {

                path: '/song/:id',
                name: 'song',
                meta: {title: 'Suno音乐播放'},
                component: () => import('@/views/Song.vue'),
            },
            {

                path: '/luma',
                name: 'luma',
                meta: {title: 'Luma视频创作'},
                component: () => import('@/views/Luma.vue'),
            },
            {

                path: '/xmind',
                name: 'xmind',
                meta: {title: '思维导图'},
                component: () => import('@/views/MarkMap.vue'),
            },
            {

                path: '/apps',
                name: 'chat-app',
                meta: {title: '应用中心'},
                component: () => import('@/views/ChatApps.vue'),
            },
            {

                path: '/images-wall',
                name: 'images',
                meta: {title: '作品展示'},
                component: () => import('@/views/ImagesWall.vue'),
            },
            {

                path: '/member',
                name: 'member',
                meta: {title: '会员充值中心'},
                component: () => import('@/views/Member.vue'),
            },
            {

                path: '/powerLog',
                name: 'powerLog',
                meta: {title: '消费日志'},
                component: () => import('@/views/PowerLog.vue'),
            },
            {

                path: '/invite',
                name: 'user-invitation',
                meta: {title: '推广计划'},
                component: () => import('@/views/Invitation.vue'),
            },
            {

                path: '/external',
                name: 'ExternalLink',
                component: () => import('@/views/ExternalPage.vue'),
            }
        ]
    },
    {
        name: "pay-return",
        path: "/payReturn",
        meta: { title: "支付回调" },
        component: () => import("@/views/PayReturn.vue"),
    },
    {
        path: '/chat/export',
        name: 'chat-export',
        meta: {title: '导出会话记录'},
        component: () => import('@/views/ChatExport.vue'),
    },
    {
        name: 'mobile',
        path: '/mobile',
        meta: {title: '首页'},
        component: () => import('@/views/mobile/Home.vue'),
        redirect: '/mobile/index',
        children: [
            {
                path: '/mobile/index',
                name: 'mobile-index',
                component: () => import('@/views/mobile/Index.vue'),
            }
        ]
    }
]

// 创建路由
const router = createRouter({
    // 路由模式
    history: createWebHistory(),
    routes: routes
})

// 上一个路由对象
let prevRoute = null

// 全局前置守卫，在每次路由跳转前 触发逻辑
// to: 即将进入的路由对象（含 path、params、meta 等属性）
// from: 当前正要离开的路由对象
// next(): 必须调用的函数以继续导航流程
router.beforeEach((to,from,next) => {
    // 设置标题
    document.title = to.meta.title
    // 设置正要离开的路由对象
    prevRoute = from
    next()
})

export {router,prevRoute}